package com.xujichang.base.extensions

import android.util.Log
import com.gp.billsrecord.BuildConfig
import java.util.concurrent.atomic.AtomicBoolean
/*打印日志，方便调试*/
object Logs {
    private val isDebug = AtomicBoolean(BuildConfig.DEBUG)

    fun config(debug: Boolean) {
        isDebug.set(debug)
    }

    fun i(tag: String, message: String, throwable: Throwable? = null) {
        if (isDebug.get()) {
            Log.i(tag, message, throwable)
        }
    }

    fun w(tag: String, message: String, throwable: Throwable? = null) {
        if (isDebug.get()) {
            Log.w(tag, message, throwable)
        }
    }

    fun e(tag: String, message: String, throwable: Throwable? = null) {
        if (isDebug.get()) {
            Log.e(tag, message, throwable)
        }
    }

    fun d(tag: String, message: String, throwable: Throwable? = null) {
        if (isDebug.get()) {
            Log.d(tag, message, throwable)
        }
    }

    fun v(tag: String, message: String, throwable: Throwable? = null) {
        if (isDebug.get()) {
            Log.v(tag, message, throwable)
        }
    }

    fun wtf(tag: String, message: String, throwable: Throwable? = null) {
        if (isDebug.get()) {
            Log.wtf(tag, message, throwable)
        }
    }
}

val Any.tag: String
    get() = this::class.simpleName ?: "NONE"